package middleware

import (
	"fx_swift_agent/pkg/code"
	"fx_swift_agent/pkg/internalerrors"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ExceptionMiddleware(c *gin.Context) {
	defer func() {
		if err := recover(); err != nil {
			// 针对panic出来的错误同意处理
			code.Fail(c, http.StatusNotAcceptable, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
			c.Abort()
		}
	}()
	c.Next()
}
